<div id="tb<?php echo $uniqid;?>" style="padding:5px">
	<table cellspacing="0" cellpadding="0">
		<tbody>
		<tr>
			<td><a href="javascript:void(0);" onclick="teamconsumelistReload();" class="l-btn l-btn-small l-btn-plain"><span
					class="l-btn-left l-btn-icon-left"><i class="iconfont icon-shuaxin"></i><span class="l-btn-text">重载</span></span></a></td>
			<td><span style="line-height:30px;">注册日期</span>
				<input id="teamconsumelistStartOn" style="width:110px" type="text" class="easyui-datebox"> </input>至
				<input id="teamconsumelistEndOn" style="width:110px" type="text" class="easyui-datebox"> </input>
			</td>
			<td>
				&nbsp;&nbsp;
			</td>
			<td>
				<select v-model="level" @change="changeLevel" class="forminput inputstyle textbox-text validatebox-text" style="width:100px">
					<option value="">全部身份</option>
					<option v-for="(vo,index) in agentLevels" :value="vo.level">{{ vo.name }}</option>
				</select></td>
			<td>
				<div class="datagrid-btn-separator"></div>
			</td>
			<td>
				<select id="teamconsumelistKeywordsType" class="forminput inputstyle textbox-text validatebox-text" style="width:80px">
					<option value="id">会员ID</option>
					<option value="nickname">会员昵称</option>
					<option value="phone">手机号</option>
				</select></td>
			<td>&nbsp;&nbsp;<input id="teamconsumelistKeywords" style="width:100px" type="text" class="easyui-input textbox"></td>
			<td><a href="javascript:void(0);" onclick="teamconsumelistSearch();" class="l-btn l-btn-small l-btn-plain"><span
					class="l-btn-left l-btn-icon-left"><i class="iconfont icon-sousuo"></i><span class="l-btn-text">查询</span></span></a></td>
<!--			<td><a href="javascript:void(0);" onclick="teamconsumelistExport();" class="l-btn l-btn-small l-btn-plain"><span-->
<!--					class="l-btn-left l-btn-icon-left"><i class="iconfont icon-xiazai"></i><span-->
<!--					class="l-btn-text">导出代理商</span></span></a></td>-->
		</tr>
		</tbody>
	</table>
</div>
<div class="con"  style="-moz-user-select:none;">
	<table id="teamconsumelist"></table>
</div>
<div id="teamconsumelistDlg" class="easyui-dialog" style="width:840px; height:520px;" title="信息框" closed="true"></div>
<script>
	var teamConsumeLogs = function (nickname, id) {
		let name = nickname || ($('#teamconsumelist').datagrid('getSelected') && $('#teamconsumelist').datagrid('getSelected').nickname);
		let rowId = id || ($('#teamconsumelist').datagrid('getSelected') && $('#teamconsumelist').datagrid('getSelected').id);
		if (rowId) {
			$("#teamconsumelistDlg").dialog({
				title: name + '-团队业绩 调整明细',
				closed: false,
				width: 940,
				height: 560,
				cache: false,
				href: '/admin/agent/teamconsumeadjustlog?id=' + rowId + '&name=' + name,
				modal: true,
				buttons: [{
					text: '关闭',
					iconCls: 'icon-no',
					handler: function () {
						$("#teamconsumelistDlg").dialog('close');
					}
				}]
			});
		} else {
			$.messager.alert('提示', '请先选择要查看的记录！', 'warning');
		}
	};

	var teamConsumeAdjust = function (nickname, id) {
		let name = nickname || ($('#teamconsumelist').datagrid('getSelected') && $('#teamconsumelist').datagrid('getSelected').nickname);
		let rowId = id || ($('#teamconsumelist').datagrid('getSelected') && $('#teamconsumelist').datagrid('getSelected').id);
		if (rowId) {
			$("#teamconsumelistDlg").dialog({
				title: name + '-团队业绩调整',
				closed: false,
				width: 720,
				height: 420,
				cache: false,
				href: '/admin/agent/teamconsumeadjust?id=' + rowId + '&name=' + name,
				modal: true,
				buttons: [{
					text: '保存',
					id: 'memberteamconsumeadjustsubmit',
					iconCls: 'icon-ok',
				}, {
					text: '关闭',
					iconCls: 'icon-no',
					handler: function () {
						$("#teamconsumelistDlg").dialog('close');
					}
				}]
			});
		} else {
			$.messager.alert('提示', '请先选择要调整的代理商！', 'warning');
		}
	};
	
	var teamconsumelistVm = new Vue({
		el: '#tb<?php echo $uniqid;?>',
		data: {
			level: '',
			agentLevels: JSON.parse('<?php echo addslashes($agentLevel);?>'),
		},
		methods: {
			changeLevel(){
				teamconsumelistSearch();
			}
		}
	});
	var teamconsumelistReload = function () {
		$("#teamconsumelist").datagrid('reload');
	};
	var teamconsumelistSearch = function () {
		var height = $(window).height() - $(".top").height() - 46;
		var width = $(window).width() - $(".leftmenu").width() - 8;
		$("#teamconsumelist").datagrid({
			title: '代理商团队业绩表',
			width: width,
			height: height,//高度
			singleSelect: true,//如果为true，则只允许选择一行
			striped: true,//是否显示斑马线效果。
			rownumbers: false,//如果为true，则显示一个行号列。
			pagination: true,//是否显示分页
			pageSize: 10,
			pageList: [10, 15, 20, 25],
			method: 'post',
			sortName: 'id',
			sortOrder: 'desc',
			idField: 'id',
			url: '/admin/agent/teamconsumelist',
			queryParams: {
				start_on: $('#teamconsumelistStartOn').val(),
				end_on: $('#teamconsumelistEndOn').val(),
				level: teamconsumelistVm.level,
				keywordsType: $('#teamconsumelistKeywordsType').val(),
				keywords: $('#teamconsumelistKeywords').val(),
			},
			fitColumns: true,//真正的自动展开/收缩列的大小，以适应网格的宽度，防止水平滚动。
			nowrap: true,//如果为true，则在同一行中显示数据。设置为true可以提高加载性能。 是否换行
			selectOnCheck: false,
			checkOnSelect: true,
			toolbar: '#tb<?php echo $uniqid;?>',
			columns: [[
				{field:'id',title:'ID',width:'5%'},
				{field:'avatar',title:'头像',width:'5%',formatter:function (value,rowData,rowIndex){
						return value ? "<img height='50px' src='"+value+"'>" : '';
					}},
				{field:'nickname',title:'用户',width:'10%'},
				{field:'phone',title:'手机号',width:'10%'},
				{field:'level_info',title:'身份',width:'10%', formatter(value, rowData){
					return value ? value.name : '普通会员';
					}},
				{field: 'team_consume', title: '团队业绩', width: '8%', sortable: true, formatter: function (value, rowData, rowIndex) {
						return value > 0 ? value : 0;
					}},
				{field:'status',title:'状态',width:'8%',formatter:function (value,rowData,rowIndex){
						return value ? '显示' : '隐藏';
					}},
				{field:'created_at',title:'加入时间',width:'10%',sortable:true},
				{field: 'options', title: '操作', width: fixWidth(20), align: "center", halign: 'center', formatter: function (value, rowData, rowIndex) {
						let buttons = '<div class="table">';
						buttons += '<span class="l-btn l-btn-small l-btn-left color9 table" onclick="teamConsumeAdjust(\'' + rowData.nickname + '\',\'' + rowData.id + '\')"><span class="l-btn-text">调整业绩</span></span>';
						buttons += '<span class="l-btn l-btn-small l-btn-left color9 table" onclick="teamConsumeLogs(\'' + rowData.nickname + '\',\'' + rowData.id + '\')"><span class="l-btn-text">调整明细</span></span>';
						return buttons + '</div>';
					}},
			]],
		});
	};
	onDatagridResize("#teamconsumelist");
	teamconsumelistSearch();
</script>
